﻿/*!
 *  @brief     自定义线程
 *  @details   对std::thread进行封装
 *  @author
 *  @version   v1.0
 *  @date      2022-03-03
 *  @copyright
 *  @note
 */
#ifndef CUSTOMTHREAD_H
#define CUSTOMTHREAD_H

#include <thread>
#include <string>
#include <iostream>

using namespace std;

namespace Common {

	typedef std::function<void()> ThreadFunc;

	class CustomThread
	{
	public:
		CustomThread(const ThreadFunc func, const string & tname);
		~CustomThread();

		void start();
		void join();

		bool isStarted() const { return m_started; }
		bool joinable();

	private:
		bool m_started;

		std::thread m_thread;

		ThreadFunc m_func;
		string m_threadName;
	};

} //namespace Common

#endif // CUSTOMTHREAD_H
